<!DOCTYPE html>
<html>
<head>
    <title>外部系统注册列表</title>
    <#include "/common/import.ftl" >
    <script type="text/javascript">
        $(function () {
            //获取外部系统注册列表
            $('#sysList').datagrid({
                title: '外部系统注册列表',
                iconCls: 'icon-ok',
                url: '${ctx}/passport/ssosys/list!data.action',
                nowrap: false,
                striped: true,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [15, 20, 30, 50],
                idField: 'sysId',
                columns: [[
                    {field: 'sysEname', title: '系统英文名', width: 60, sortable: true},
                    {field: 'sysCname', title: '系统中文名称', width: 80, sortable: true},
                    {field: 'sysAccreditename', title: '系统创建人', width: 80, sortable: true},
                    {
                        field: 'sysOwtype', title: '系统内外部标示', width: 60, sortable: true,
                        formatter: function (value) {
                            if (value == '0') {
                                return '<font color=#8B008B>内部</font>';
                            }
                            else {
                                return '<font color=#6A5ACD>外部</font>';
                            }
                        }
                    },
                    {field: 'sysAccreditip', title: '外部系统IP', width: 130, sortable: true},
                    {field: 'sysRemark', title: '系统备注', width: 100, sortable: true},
                    {
                        field: 'sysStatus', title: '系统状态', width: 40, sortable: true,
                        formatter: function (value) {
                            if (value == '0') {
                                return '<font color=#66CD00>正常</font>';
                            }
                            else {
                                return '<font color=red>冻结</font>';
                            }
                        }
                    }
                ]],
                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        saveSys();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        deleteSys();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editSys();
                    }
                }, '-', {
                    text: '刷新',
                    iconCls: 'icon-reload',
                    handler: function () {
                        sysReload();
                    }
                }
                ],
                onDblClickRow: function () {
                    dataItemTree();
                }
            });
        });

        // 进入增加页面
        function saveSys() {
            $('#saveFrame').html('');
            var url = '${ctx}/passport/ssosys/sys-save';
            $('#saveFrame').attr("src", url);
            $('#saveDiv').window('open');
        }

        // 进入修改页面
        function editSys() {
            var node = getSelected();
            if (node) {
                var url = '${ctx}/passport/ssosys/sys-save?sysId=' + node.sysId;
                $('#saveFrame').attr("src", url);
                $('#saveDiv').window('open');
            }
        }

        // 判断是否选中一条记录
        function getSelected() {
            var selected = $('#sysList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        //清空查询数据库,并重新查询
        function clearSearch() {
            $('#sysEname').val('');
            $('#sysCname').val('');
            $('#sysOwtype').val('');
            $('#sysStatus').val('');
            searchList();
        }

        // 点击取消按钮，关闭添加窗口
        function colseAdd() {
            $('#saveDiv').window('close');
        }

        // 刷新列表
        function sysReload() {
            $('#sysList').datagrid('reload');
        }

        //查询
        function searchList() {
            var queryParams = $('#sysList').datagrid('options').queryParams;
            var opt = $('#sysList').datagrid('getPager').data("pagination").options;
            $('#sysList').datagrid('options').pageNumber = 1;
            queryParams["sysEname"] = $('#sysEname').val();
            queryParams["sysCname"] = $('#sysCname').val();
            queryParams["sysOwtype"] = $('select#sysOwtype option:selected').val();
            queryParams["sysStatus"] = $('select#sysStatus option:selected').val();
            $('#sysList').datagrid('reload');
            var page = $('#sysList').datagrid('getPager');
            page.pagination({pageNumber: 1, pageSize: opt.pageSize});
        }

        //删除，物理删除
        function deleteSys() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color=red>' + node.sysEname + '</font> ?', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/passport/ssosys/del.action?sysId=" + node.sysId,
                            dataType: "json",
                            success: function (data) {
                                var result = data;//jQuery.parseJSON(data);
                                if (result.flag == 'T') {
                                    $.messager.alert('结果', '操作成功', 'info');
                                    var rowIndex = $('#sysList').datagrid('getRowIndex', node);
                                    $('#sysList').datagrid('deleteRow', rowIndex);
                                } else if (result.flag == 'H') {
                                    $.messager.alert('结果', result.msg, 'info');
                                } else {
                                    $.messager.alert('结果', '操作失败，请重试', 'error');
                                }
                            },
                            error: function (messg) {
                                $.messager.alert('错误提示', '操作失败:' + messg.responseText, 'error');
                            }
                        });
                    }
                });
            }
        }
    </script>
</head>
<body>
<table class="datagrid-body" style="font-size: 12px" width="100%">
    <tr>
        <td class="datagrid-header">系统英文名称</td>
        <td><input type="text" id="signEname" name="signEname"/></td>
        <td class="datagrid-header">系统中文名称</td>
        <td><input type="text" id="signState" name="signState"/></td>
        <td class="datagrid-header">系统内外部标识</td>
        <td>
            <select name="sysOwtype" id="sysOwtype">
                <option value="">全部</option>
                <option value="0">内部</option>
                <option value="1">外部</option>
            </select>
        </td>
        <td class="datagrid-header">系统状态</td>
        <td>
            <select name="sysStatus" id="sysStatus">
                <option value="">全部</option>
                <option value="0">正常</option>
                <option value="1">冻结</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="8" align="center">
            <a class="easyui-linkbutton" iconCls="icon-search" onclick="searchList()">查 询</a>
            <a class="easyui-linkbutton" iconCls="icon-undo" href="javascript:void(0)"
               onclick="clearSearch();">清空</a>
        </td>
    </tr>
</table>
<table id="sysList"></table>

<!-- 添加窗口 -->
<div id="saveDiv" class="easyui-window" title="添加外部系统"
     style="padding:5px;width: 500px;height:400px;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe frameborder="0" id="saveFrame" height="100%" width="100%" scrolling="No"
            frameborder="0"></iframe>
</div>

</body>
</html>